{
	template:`
    <m-page @back="back" title="店铺结算">
        <template #bar>
            <div class="padding-left">
                <status type="settleStatus" :value="model.status"></status>
            </div>
            <div class="flex-sub padding-lr text-sm text-right">
            </div>
            <div class="m-buttons padding-right">
                <m-button v-if="model.oid&&model.status=='N'&&editable" @click="next('delete','确定要删除吗？')" type="error">删除</m-button>
                <m-button v-if="editable" @click="save(true)" type="success">提交</m-button>
                <m-button v-if="model.oid&&confirmable" @click="next('back','确定要退回吗？')" type="warn">退回</m-button>
                <m-button v-if="model.oid&&confirmable" @click="next('confirm','确定要审核通过吗？')" type="success">确认</m-button>
            </div>
        </template>
        <m-top></m-top>
        <m-title>结算信息</m-title>
        <m-card>
            <div class="cu-form-group">
                <div class="title">登记店铺</div>
                <div class="cu-tag radius" :class="'bg-'+model.inputStore.color">{{model.inputStore.name}}</div>
                <div class="flex-sub padding-left-sm">
                    <span>{{model.inputStore.tel}}</span>
                    <div class="text-sm">{{model.inputStore.address}}</div>
                </div>
            </div>
            <div class="cu-form-group">
                <div class="title">结算给</div>
                <div class="cu-tag radius" :class="'bg-'+model.settleStore.color">{{model.settleStore.name}}</div>
                <div class="flex-sub padding-left-sm">
                    <span>{{model.settleStore.tel}}</span>
                    <div class="text-sm">{{model.settleStore.address}}</div>
                </div>
            </div>
            <div v-if="editable" class="cu-form-group">
                <div class="flex-sub text-red">选择结算明细计算结算金额</div>
                <div><m-button @click="addRechargeOffset()" type="success">选择结算明细</m-button></div>
            </div>
            <div class="cu-form-group">
                <div class="flex-sub text-right">付款金额：</div>
                <div class="text-lg text-red">{{formatAmount(model.payAmount)}}</div>
                <div>元</div>
                <div class="flex-sub text-right">赠送金额：</div>
                <div class="text-lg text-red">{{formatAmount(model.giveAmount)}}</div>
                <div>元</div>
            </div>
            <div class="cu-form-group">
                <div class="text-blue flex-sub text-right" @click="rechargeOffsetList">查看结算明细</div>
                <div class="padding-left-sm">结算金额：</div>
                <div class="text-xl text-red">{{formatAmount(model.settleAmount)}}</div>
                <div>元</div>
            </div>
            <div class="cu-form-group">
                <div class="title">备注</div>
                <m-input type="textarea" :operable="editable" v-model="model.remark" placeholder="请输入备注"></m-input>
            </div>
            <div class="cu-form-group">
                <div class="title">确认备注</div>
                <m-input type="textarea" :operable="confirmable" v-model="model.remark" placeholder="请输入备注"></m-input>
            </div>
        </m-card>
        <m-title>登记确认信息</m-title>
        <m-card>
            <m-grid :col="2" class="flex-sub">
                <m-desc title="登记员工">{{model.inputUser.realName}}<small>{{model.inputUser.phoneNum}}</small></m-desc>
                <m-desc title="登记时间">{{formatDate(model.inputDate,'yyyy-MM-dd HH:mm')}}</m-desc>
                <m-desc title="确认员工">{{model.confirmUser.realName}}<small>{{model.confirmUser.phoneNum}}</small></m-desc>
                <m-desc title="确认时间">{{formatDate(model.confirmDate,'yyyy-MM-dd HH:mm')}}</m-desc>
            </m-grid>
        </m-card>
    </m-page>
	`,
	props: ['param','parentVue'],
	data:function(){
		return {
		    model:{inputStore:{},settleStore:{},inputUser:{},confirmUser:{}},
		    editable:false,
		    confirmable:false
		};
	},
	mounted(){
	    this.model.oid=this.param.oid;
	    this.loadModel();
	},
	methods:{
	    loadModel:function(fn){
            this.requestData('action/order/storeSettle/getInfo',
                {oid:this.model.oid},
                (data)=>{
                    if(data.code==0){
                        this.model=data.model;
                        this.editable=data.editable;
                        this.confirmable=data.confirmable;
                        if(fn) fn();
                    }else{
                        this.remind().error(data.msg);
                    }
                }
            );
	    },
	    addRechargeOffset:function(){
	        this.openPage('order/settle/addRechargeOffsetList.js',
                {settleOid:this.model.oid,inputStoreOid:this.model.inputStore.oid,settleStoreOid:this.model.settleStore.oid},
                (flag,obj)=>{
                    let remark=this.model.remark;
                    this.loadModel(()=>{
                        this.model.remark=remark;
                    });
                }
	        );
	    },
	    rechargeOffsetList:function(){
	        this.openPage('order/settle/rechargeOffsetList.js',
                {settleOid:this.model.oid,inputStoreOid:this.model.inputStore.oid},
                (flag,obj)=>{
                }
	        );
	    },
        save:function(isSubmit){
            let fn=()=>{
                this.requestData('action/order/storeSettle/'+(isSubmit?'submit':'save'),
                    {model:this.model},
                    (data)=>{
                        if(data.code==0){
                            this.remind().success(data.msg);
                            this.model.oid=data.oid;
                            if(isSubmit){
                                this.back(true,this.model);
                            }else{
                                this.loadModel(()=>{
                                    this.setBack(true,this.model);
                                });
                            }
                        }else{
                            this.remind().error(data.msg);
                        }
                    }
                );
            }
            if(isSubmit){
                this.confirm("保存并提交","确定要保存并提交吗？",fn);
            }else{
                fn();
            }
        },
        next:function(oper,confirmAlert){
            this.confirm('操作提示',confirmAlert||'确定要这样操作吗？',()=>{
                this.requestData('action/order/storeSettle/'+oper,
                    {model:this.model},
                    (data)=>{
                        if(data.code==0){
                            this.remind().success(data.msg);
                            this.back(true,this.model);
                        }else{
                            this.remind().error(data.msg);
                        }
                    }
                );
            });
        }
	}
}